package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.FindWorkerSearchEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
*@author 李昭
*@date 2020/9/14
*description:
*/
public class FindWorkerSearchAdapter extends BaseRecycleAdapter<FindWorkerSearchEntity> {

    private RequestManager requestManager;

    public FindWorkerSearchAdapter(Context context, List<FindWorkerSearchEntity> data, RequestManager requestManager) {
        super(context, R.layout.item_find_worker_search, data);
        this.requestManager = requestManager;
    }

    @Override
    public void convert(ItemViewHolder holder, FindWorkerSearchEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ImageView ivWorkerAvatar = holder.itemView.findViewById(R.id.iv_worker_avatar);
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.worker_avatar)
                .transforms(new CenterCrop(), new RoundedCorners(8));
        if (TextUtils.isEmpty(entity.getAvatarAddress())) {
            requestManager.load(R.mipmap.worker_avatar).into(ivWorkerAvatar);
        } else {
            requestManager.load(entity.getAvatarAddress()).apply(options).into(ivWorkerAvatar);
        }
        TextView tvInfo = holder.itemView.findViewById(R.id.tv_info);
        if (entity.getSex() == 1) {
            tvInfo.setText(String.format("男  |  %s岁", entity.getAge()));
        } else {
            tvInfo.setText(String.format("女  |  %s岁", entity.getAge()));
        }
        TextView tvTime = holder.itemView.findViewById(R.id.tv_time);
        tvTime.setText(DateUtils.timestampToDate(entity.getCreateTime()));
        TextView findWorkerKind = holder.itemView.findViewById(R.id.find_worker_kind);
        //种族
        String nationName = entity.getNationName();
        //工龄
        String workYear = entity.getWorkYear();
        //工种
        String proficiencyName = entity.getProficiencyName();
        //行业类型
        String industryName = entity.getIndustryName();
        StringBuilder stringBuilder = new StringBuilder();
        if (!TextUtils.isEmpty(nationName)) {
            stringBuilder.append(nationName).append(" | ");
        }
        if (!TextUtils.isEmpty(workYear)) {
            stringBuilder.append(workYear).append(" | ");
        }
        if (!TextUtils.isEmpty(proficiencyName)) {
            stringBuilder.append(proficiencyName).append(" | ");
        }
        if (!TextUtils.isEmpty(industryName)) {
            stringBuilder.append(industryName);
        }
        findWorkerKind.setText(stringBuilder.toString());
        if (null == entity.getTypeWorkName() || TextUtils.isEmpty(entity.getTypeWorkName())) {
            holder.itemView.findViewById(R.id.tv_work_type).setVisibility(View.GONE);
        } else {
            holder.itemView.findViewById(R.id.tv_work_type).setVisibility(View.VISIBLE);
        }
        ImageView certifications = holder.itemView.findViewById(R.id.certification);
        if (!TextUtils.isEmpty(entity.getFileName())) {
            certifications.setVisibility(View.VISIBLE);
        } else {
            certifications.setVisibility(View.GONE);
        }
    }
}
